package org.example;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class ServiceConsumer {
    private RestTemplate restTemplate;

    public ServiceConsumer(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping(value = "/{string}")
    public String echo(@PathVariable String string) {
        String resp = restTemplate.getForObject("http://nacos-discovery-service-provider/service/" + string, String.class);
        return "Consumer: " + resp;
    }
}
